import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class UCRNSTester {

	Environment anEnvironment;
	Agent anAgent;
	Spectrum aSpectrum;
	CognitiveRadio aCR;
	
	@Before
	public void setUp() {
		anEnvironment = new Environment(10);
		aCR = new CognitiveRadio("CR0", anEnvironment, Role.RECEIVER, Method.RANDOM);
		aSpectrum = new Spectrum(15);
	}
	
	@Test
	public void testSpectrumOccupation() {
		aCR.occupySpectrum(aSpectrum);
		assertTrue(aCR.currentState.occupiedSpectrum.equals(aSpectrum));
		assertTrue(aSpectrum.occupyingAgents.size() == 1);
	}
	
	@Test
	public void testSpectrumVacation() {
		assertTrue(aSpectrum.occupyingAgents.size() == 0);
		aCR.occupySpectrum(aSpectrum);
		assertTrue(aSpectrum.occupyingAgents.size() == 1);
		aCR.vacateSpectrum();
		assertTrue(aSpectrum.occupyingAgents.size() == 0);
	}

	@Test
	public void testSpectrumAndAgentEquity() {
		aCR.occupySpectrum(aSpectrum);
		assertTrue(aSpectrum.occupyingAgents.size() == 1);		
		assertTrue(aCR.currentState.occupiedSpectrum.equals(aSpectrum));
		assertTrue(aSpectrum.occupyingAgents.contains(aCR));
	}

}
